package cn.phecda.boot.data.jpa.hibernate;

import cn.phecda.boot.common.lang.util.SnowflakeUtils;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;

/**
 * <p>Jpa 雪花算法ID生成器, 支持String类型</p>
 *
 *  使用方法:
 *  <pre>
 *     &#64;Id
 *     &#64;GenericGenerator(name="SnowflakeGenerator", type = SnowflakeGenerator.class)
 *     &#64;GeneratedValue(generator = "SnowflakeGenerator")
 *     &#64;Column(name = "definition_id")
 *     private String definitionId;
 *  </pre>
 *
 * @author : wanpinwei
 */
public class SnowflakeGenerator  implements IdentifierGenerator, Configurable {
    @Override
    public Object generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) {
        return SnowflakeUtils.nextStrId();
    }
}
